home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
023a
/
adrsbar.zip
/
ADRSBAR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-06-28
|
8KB
|
401 lines
program ADRSBAR; {Based on POSTNT by Dave Barrett}
{ Date: 06-12-91 }
(*********************************************************************)
(* POSTNT was written as an exercise. The intent was to produce *)
(* a program which could print US Postal Service POSTNET barcodes *)
(* (those lines on lower right corner of some of the letters *)
(* you get in the mail) which could be used for demonstration *)
(* and information purposes. As it turned out, the barcodes *)
(* actually are 'readable' on a barcode sorter. *)
(* *)
(* *)
(* This program was written by Dave Barrett, CS 76314,1004 *)
(* This program is put in the public domain with the following *)
(* conditions: *)
(* *)
(* 1) This portion of the documentation must remain with the source. *)
(* 2) If you make any improvements to the program please post them *)
(* so others can enjoy them. *)
(* 3) This program must be distributed without charge whether used *)
(* alone or included as part of another program. *)
(* 4) Please include the accompanying file POSTNT.DOC along with *)
(* this file *)
(*********************************************************************)
uses dos,crt,printer,adrsprn;
type
NumberSet = set of char;
var
infile : text;
Infilename : string[30];
CheckDigit,
ZIPString : string[200];
Afield,
Bfield : string [10];
Numbers : NumberSet;
Count,Firstcount,Lastcount,
CheckNumber,
result : integer;
ExitSave : pointer;
ZIPCodeIsValid : boolean;
procedure PrintFullBar;
begin
Write(Lst,char(255));
Write(Lst,char(255));
Write(Lst,char(255));
Write(Lst,char(255));
end;
procedure PrintFullSpace;
begin
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
end;
procedure PrintPartSpace;
begin
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
Write(Lst,char(0));
end;
procedure PrintHalfBar;
begin
Write(Lst,char(15));
Write(Lst,char(15));
Write(Lst,char(15));
Write(Lst,char(15));
end;
procedure PrintFrameBar;
begin
PrintFullBar;
PrintFullSpace;
end;
procedure Print0;
begin
PrintFullBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
end;
procedure Print1;
begin
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
end;
procedure Print2;
begin
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
end;
procedure Print3;
begin
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
end;
procedure Print4;
begin
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
end;
procedure Print5;
begin
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
end;
procedure Print6;
begin
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
end;
procedure Print7;
begin
PrintFullBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintFullBar;
PrintFullSpace;
end;
procedure Print8;
begin
PrintFullBar;
PrintFullSpace;
PrintHalfBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
PrintFullBar;
PrintPartSpace;
PrintHalfBar;
PrintFullSpace;
end;
procedure Print9;
begin
PrintFullBar; { 4 }
PrintFullSpace; { 8 }
PrintHalfBar; { 4 }
PrintPartSpace; { 7 }
PrintFullBar; { 4 }
PrintFullSpace; { 8 }
PrintHalfBar; { 4 }
PrintPartSpace; { 7 }
PrintHalfBar; { 4 }
PrintFullSpace; { 8 }
end;
procedure PrintBarCode(s:integer);
var
i : integer;
begin
PrintFrameBar;
i:=1;
while i <= Length(ZIPString) do
begin
case ZIPString[i] of
'0':Print0;
'1':Print1;
'2':Print2;
'3':Print3;
'4':Print4;
'5':Print5;
'6':Print6;
'7':Print7;
'8':Print8;
'9':Print9;
end;
i:=i+1;
end;
PrintFrameBar;
if s=1 then
else
Writeln(Lst);
end;
procedure DetermineCheckDigit;
var
zip_digit,
zip_total,
i : integer;
begin
zip_total:=0;
for i:=1 to Length(ZIPString) do
begin
Val(ZIPString[i],zip_digit,result);
zip_total:=zip_total+zip_digit;
end;
CheckNumber:=10 - (zip_total MOD 10);
Str(CheckNumber:1,CheckDigit);
ZIPString:=ZIPString+CheckDigit;
end;
procedure VerifyDigits;
var
i : integer;
begin
Numbers:=['0','1','2','3','4','5','6','7','8','9'];
ZIPCodeIsValid:=true;
if ((Copy(ZIPString,1,1)='A') OR (Copy(ZIPString,1,1)='a'))
AND ((Copy(ZIPString,2,1)='B') OR (Copy(ZIPString,2,1)='b'))
AND (Length(ZIPString)=13) then
ZIPString:=Copy(ZIPString,3,11);
if (Length(ZIPString)=5) then
begin
for i:=1 to 5 do
if ZIPString[i] in Numbers then
begin end
else
ZIPCodeIsValid:=false;
end
else
if (Length(ZIPString)=9) then
begin
for i:=1 to 9 do
if ZIPString[i] in Numbers then
begin end
else
ZIPCodeIsValid:=false;
end
else
if (Length(ZIPString)=10) AND (Pos('-',ZIPString)=6) then
begin
Delete(ZIPString,6,1);
for i:=1 to 9 do
if ZIPString[i] in Numbers then
begin end
else
ZIPCodeIsValid:=false;
end
else
if (Length(ZIPString)=11) then
begin
for i:=1 to 11 do
if ZIPString[i] in Numbers then
begin end
else
ZIPCodeIsValid:=false;
end
else
ZIPCodeIsValid:=false;
end;
procedure PrintAddress; {This section added by R.B. Shreve, W8GRG, 6/12/91}
begin
WriteLn(Lst,FirstName+' '+LastName); {from ADRSPRN.PAS}
WriteLn(Lst,Address);
WriteLn(Lst,City+' '+State+' '+Zip)
end;
procedure Initialization;
begin
Clrscr;
GotoXY(10,5);
Write('Enter name of address file..'); {modification by R.B. Shreve to}
Read(infilename); {read address from ASCII list..}
Assign(infile, infilename);
{$I-}
Reset(infile);
{$I+}
If IOResult <> 0 then WriteLn('File not found');
GotoXY(10,7);
Write('Enter starting record number...'); {permits printing part of file}
ReadLn(Firstcount);
GotoXY(10,8);
Write('Enter ending record number...');
ReadLn(Lastcount);
end;
{$F+}
procedure MyExit;
begin
ExitProc:=ExitSave;
gotoXY(12,12);
WriteLn('End of File');
Close(infile);
end;
{$F-}
begin
ZIPString:='';
Count:=1;
Initialization;
While not EOF(infile) do
begin
if (count>=firstcount) and (count<=lastcount) then
begin
GetAdr(infile);
ZIPString:=Zip;
VerifyDigits;
if ZIPCodeIsValid then
begin
PrintAddress;
DetermineCheckDigit;
if Length(ZIPSTring) = 6 then
Write(Lst,char(27),'Z',char(116),char(1))
else
Write(Lst,char(27),'Z',char(92),char(2));
PrintBarCode(0); { CR/LF ok }
WriteLn(Lst,char(27),'I',2);
WriteLn(Lst);
end;
end;
Inc(count);
if count>lastcount then
begin
Halt;
ExitSave:=ExitProc;
ExitProc:=@MyExit;
end;
end;
end.